<?php
require_once "include/function.php";
connect_db();


//include("Connection.php");

class Register
	{
		//ADD Function
		private $venderID,$username,$password,$address,
		$email,$s_name,$f_name,$title,$sex,$p_code,$pic_type,
			$provinceID,$amphurID,$districtID;


                        public function setVenderID($venderID)
			{
				$this->venderID=$venderID;
			}

                         public function setFirstname($f_name)
			{
				$this->f_name=$f_name;
			}
			public function setSurname($s_name)
			{
				$this->s_name=$s_name;
			}
			public function setCode($p_code)
			{
				$this->p_code=$p_code;
			}
			public function setUsername($username)
			{
				$this->username=$username;
			}
			public function setPassword($password)
			{
				$this->password=$password;
			}
			public function setTitle($title)
			{
				$this->title=$title;
			}
			public function setSex($sex)
			{
				$this->sex=$sex;
			}
			public function setEmail($email)
			{
				$this->email=$email;
			}

			public function setProvinceID($provinceID)
			{
				$this->provinceID=$provinceID;
			}
			public function setAmphurID($amphurID)
			{
				$this->amphurID=$amphurID;
			}
			public function setDistrictID($districtID)
			{
				$this->districtID=$districtID;
			}

			public function setAddress($address)
			{
				$this->address=$address;
			}
			public function setPic($pic_type)
			{
				$this->picType=$pic_type;
			}
			public function addRecord()
			{
				$sql="INSERT INTO venders (v_username,v_password,v_email,v_address,v_name,v_surname,v_title,v_sex,v_picture_type,v_personal,v_PROVINCE_ID,v_AMPHUR_ID,v_DISTRICT_ID) VALUES ('$this->username',md5('$this->password'),'$this->email','$this->address','$this->f_name','$this->s_name','$this->title','$this->sex','$this->picType','$this->p_code',$this->provinceID,$this->amphurID,$this->districtID)";
				


mysql_query($sql);
				
				$id=mysql_insert_id();
				
				$filename="images/user/". $id . "." . $this->picType;
				move_uploaded_file($_FILES["user_image"]["tmp_name"],$filename);
				
				
echo "Hello " .$id;	
					
					if($id>0)
					{
						
						
						header("location:index.php");
						
					}else
					{
						header("location:venderform.php");
						
					}
					
					
			}

                        public function editRecord()
			{
				$sql="update venders 
                                

                                 set v_username='$this->username',
                                     v_password= md5('$this->password'),
                                     v_email='$this->email',
				     v_address='$this->address',
				     v_name='$this->f_name',
				     v_surname='$this->s_name',
				     v_title='$this->title',
				     v_sex='$this->sex',
				     v_picture_type='$this->picType',
				     v_personal='$this->p_code',
				     v_PROVINCE_ID=$this->provinceID,
				     v_AMPHUR_ID=$this->amphurID,
				     v_DISTRICT_ID=$this->districtID
                                  where v_id=$this->venderID ";

				mysql_query($sql);
				
				$id=mysql_update_id();
				
				$filename="images/vender/". $id . "." . $this->picType;
				move_uploaded_file($_FILES["user_image"]["tmp_name"],$filename);
				
					
					
					if($id>0)
					{
						
						
						header("location:index.php");
						
					}else
					{
						header("location:venderprofile.php");
						
					}
					
					
			}
			public function validateUser()
				{
					$sql="SELECT * FROM venders WHERE v_name='$this->username'";
					$result=mysql_query($sql);
					if(mysql_num_rows($result)>0)
						{
							echo "<font color='red'>Username has already been taken </font>";
						}
					else
						{
							echo "<font color='green'>Username has avalaible </font>";
						}
				}
	}
			
